﻿using KAKA.Domain;
using Morus.Infrastructure;
using System;
using System.Collections.Generic;
using System.Linq;

namespace KAKA.Repository
{
    public interface IEventRepository : IRepository<Event>
    {
        Event Get(Guid id);

        IEnumerable<Event> GetAll();
        IEnumerable<Event> Find(ISpecification<Event> specification);
    }

    public class EventRepository : Repository<Event>, IEventRepository
    {
        public EventRepository(Database database)
            : base(database)
        {
        }

        public Event Get(Guid id)
        {
            return base.Get(Spec<Event>.Eval(r => r.Id == id));
        }

        public new IEnumerable<Event> GetAll()
        {
            return this.Find(Spec<Event>.Any()).ToArray();
        }

        public new IEnumerable<Event> Find(ISpecification<Event> specification)
        {
            return base.Find(specification.And(new UndeleteEventSpecification())).ToArray();
        }
    }
}
